<?php
/*
 * @Author: your name
 * @Date: 2021-09-21 16:46:35
 * @LastEditTime: 2022-01-16 21:33:32
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /nlog/app/Http/Controllers/AdminController/Login.php
 */

namespace App\Http\Controllers\admin_controller;

use Illuminate\Support\Facades\Request;
use  App\Models\admin_model\DailyParttimeUser as DailyParttimeUserDb;
class DailyParttimeUser extends BaseController
{
    
    public function userList(){
        if (Request::has('keyWord')) {
            $whereStr = '';
            $limitStr = '';
            if (Request::input('pageSize') && Request::input('page')) {
                $limitStr =   limit_joint(Request::input('page'), Request::input('pageSize'));
            }
            $keyWord = array_filter(Request::input('keyWord'), 'filtrfunction');
            if (!empty($keyWord)) {
                $whereStr .= ' WHERE '.havaWhereLikeJoinEqual($keyWord,false);
            }
                $list  =   DailyParttimeUserDb::list($whereStr, $limitStr);
                $count =   DailyParttimeUserDb::count($whereStr);
                return $this->create(200, '查询成功', ['list' => $list, 'total' => $count[0]['count']]);
        }  else{
              return missingParameter();
        } 
    }

    public function userBind(){
        if(Request::has('id')){
            $user_id = Request::input('id');
            $adminId =  $this->getAdminId();
            $res =  redis_mysql_edit_return('daily_parttime_user',['id'=>$user_id,'is_customer'=>1,'customerAdmins_id'=>0],['is_customer'=>0,'customerAdmins_id'=> $adminId ]);
            if($res){
                return $this->create(200,'绑定成功');
            }else{
                return $this->create(100,'绑定失败');
            }
        }
         

    }

    public function clearUserBind(){
        if(Request::has('id')){
            $user_id = Request::input('id');
            // $adminId =  $this->getAdminId();
            // $res =  redis_mysql_edit_return('daily_parttime_user',['id'=>$user_id,'is_customer'=>0,'customerAdmins_id'=> $adminId],['is_customer'=>1,'customerAdmins_id'=> 0 ]);
            $res =  redis_mysql_edit_return('daily_parttime_user',['id'=>$user_id,'is_customer'=>0],['is_customer'=>1,'customerAdmins_id'=> 0 ]);
            if($res){
                return $this->create(200,'解绑成功');
            }else{
                return $this->create(100,'解绑失败');
            }
        }
    }


    

}
